<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\service\ApiService;
use cmf\controller\HomeBaseController;
use app\portal\model\PortalCategoryModel;
use think\Request;

class ListController extends HomeBaseController
{
    public function index(Request $request)
    {
        $id = $this->request->param('id', 0, 'intval');
        $portalCategoryModel = new PortalCategoryModel();

        $category = $portalCategoryModel->where('id', $id)->where('status', 1)->find();

        $nav = getnav();
        $this->assign('nav',$nav);
        $this->assign('category', $category);

        /*--xuanfeng_read_category_all--start--*/
        $cate_list = db('portal_category')->where("parent_id=$id and status=1")->order("list_order desc")->select();
        //echo db('portal_post')->getLastSql();
        $this->assign('catelist',$cate_list);

        /*--获取参数--*/
        $param_ary = $request->param();
        if(empty($param_ary['page'])){
            $param_ary['page'] = 1;
        }
        $this->assign('param_ary',$param_ary);


        if(!empty($param_ary['tid'])){
            $where = ["pid"=>$id,"cid"=>$param_ary['tid'],"post_status" => 1];
        }else{
            $where = ["pid"=>$id,"post_status" => 1];
        }

        /**搜索条件**/

        if($id == 2){
            $articles = db('newscates')->where($where)->order("is_top DESC")->paginate(10);
        }else{
            $articles = db('newscates')->where($where)->order("is_top DESC")->paginate(2);
        }

        //var_dump($articles->toArray());die;
        // 获取分页显示
        $page = $articles->render();

        $this->assign("page", $page);
        $this->assign("articles", $articles);

        $listTpl = empty($category['list_tpl']) ? 'list' : $category['list_tpl'];
        return $this->fetch('/' . $listTpl);
    }



}
